home *** CD-ROM | disk | FTP | other *** search
-
-
- {Allows access to the Real mode memory (lower 1MB of physical address space).
- Uses the DPMI.
-
-
- Rex K. Perkins, CIS 70651,1611
-
-
- 10th April 1992}
-
-
-
- Unit Real_Mem;
-
- Interface
-
- Uses WinProcs,WinTypes;
-
- Type
- PRealSegment=^TRealSegment;
- TRealSegment=Array[0..65534] Of Byte;
-
-
- Function GetSelector(RequiredSegment:Word):Word;
-
- {If we have not already got a selector, allocate one, otherwise move the
- current selector to this segment. Returns the selector. No error trap}
-
-
- Function GetRealSegment(RequiredSegment:Word):PRealSegment;
-
- {Get a pointer to a 64K (less 1 byte) array in real address space.
- Note that any pointer obtained with this function WILL become invalid
- next time function is called.}
-
-
- Implementation
-
-
- Var Selector:Word; {The real mode selector when SelectorValid}
- SelectorValid:Boolean; {True if we have a selector}
-
-
-
- Function GetSelector(RequiredSegment:Word):Word;
-
- {If we have not already got a selector, allocate one, otherwise move the
- current selector to this segment. Returns the selector. No error trap}
-
-
- Function MakeDescriptor(RequiredSegment:Word):Word;
-
- {Use the DPMI to create a protected mode descriptor for the specified
- real mode segment, and return the selector for it. Use sparingly, as the
- descriptor can't be freed}
-
- Var Selector:Word;
-
- Begin
- ASM
- push di
- push es
-
- mov bx,RequiredSegment {Pass the segment to the DPMI}
- mov ax,$0002 {DPMI function number}
- int 31h {Call the DPMI}
-
- {If the carry flag was set, there was an error}
- mov selector,ax {Get the selector. Not valid if CF}
- pop es
- pop di
- End;
- MakeDescriptor:=Selector
- End;
-
-
-
- Procedure MoveSelector(RequiredSegment,Selector:Word);
-
- {Use the DPMI to move the mapping for the specified selector to an alternative
- real mode segment.}
-
- Var SelectorLocal,SegmentHi,SegmentLo:Word;
-
- Begin
- SegmentLo:=RequiredSegment SHL 4; {Get the 32 bit base address}
- SegmentHi:=RequiredSegment SHR 12;
- SelectorLocal:=Selector;
-
- ASM
- push di
- push es
-
- mov bx,SelectorLocal {Selector to change}
- mov cx,SegmentHi {High 16 bits of base address}
- mov dx,SegmentLo {Low 16 bits of base address}
- mov ax,$0007 {DPMI function number}
- int 31h {Call the DPMI}
-
- {If the carry flag was set, there was an error}
- pop es
- pop di
- End
- End;
-
-
-
-
- Begin
- If SelectorValid Then
- MoveSelector(RequiredSegment,Selector) {We have a selector, so move it}
- Else
- Begin
- Selector:=MakeDescriptor(RequiredSegment); {Make a new descriptor at the address RequiredSegment:0}
- SelectorValid:=True
- End;
- GetSelector:=Selector
- End;
-
-
-
-
- Function GetRealSegment(RequiredSegment:Word):PRealSegment;
-
- {Get a pointer to a 64K (less 1 byte) array in real address space.
- Note that any pointer obtained with this function WILL become invalid
- next time function is called.}
-
- Begin
- GetRealSegment:=PTR(GetSelector(RequiredSegment),0)
- End;
-
-
-
- Begin
- SelectorValid:=False {We have no selector yet!}
- End.
-
-